public class MyQueue1 {
    static class ListNode{
       private int val;
       private ListNode prev;
       private ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
     private ListNode front;
     private ListNode rear;
    private int useSize;

    public void offer(int val){
         ListNode newnode=new ListNode(val);
         if(front==null){
             front=rear=newnode;
         }else{
             newnode.next=front;
             front.prev=newnode;
             front=newnode;
         }
         useSize++;
     }
     //尾删除
    public int poll( ){
        if(rear==null){
            return -1;
        }
        int ret=rear.val;
        if(rear==front){
            rear=null;
            front=null;
        }
        else {
            rear = rear.prev;
            rear.next = null;
        }
        return ret;
    }
    public int peek(){
        if(front==null){
            return -1;
        }
        return front.val;
    }
    public int getUseSize(){
        return useSize;
    }
    public boolean empty(){
        return useSize==0;
    }
}
